package com.lesama.test;

public class ArrayTest1 {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 7, 6, 8, 3, 4, 9, 10, 2};
        System.out.println(getMaxNum(arr));
        System.out.println(getMinNum(arr));
        System.out.println(getAvg(arr));
        System.out.println(countAvg(arr));
    }
    public static int getMaxNum(int[] arr) {
        int n = arr.length;
        if(n == 0) {
            return 0;
        }
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            max = Math.max(max, arr[i]);
        }
        return max;
    }
    public static int getMinNum(int[] arr) {
        if(arr.length == 0) {
            return 0;
        }
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            min = Math.min(min, arr[i]);
        }
        return min;
    }
    public static double getAvg(int[] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum / (double)arr.length;
    }
    public static int countAvg(int[] arr) {
        double avg = getAvg(arr);
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] < avg) {
                count++;
            }
        }
        return count;
    }
}
